<?php
/**
 * 涂原料管理
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-30
 */
namespace Admin\Controller;

class MaterialController extends CommonController{
    /*
     * 构造函数
     * 
     * @return #
     */
    public function _initialize() {
        parent::_initialize();
        $this->db   =new \Model\MaterialModel();
    }
    
    /*
     * 材料列表
     * 
     * @return #
     */
    public function index(){
        $map=$this->_search("Material");
        $materialList   =$this->_list($this->db,$map);
        $this->assign("mList",$materialList);
        $this->display();
    }
    
    /*
     * 显示编辑涂原料
     * 
     * @return #
     */
    public function show(){
        if(I("request.id")){
            $materialInfo   =$this->db->find(I("request.id",'',"int"));
            $this->assign("mInfo",$materialInfo);
        }
        $this->display();
    }
    
    /*
     * 编辑涂原料
     * 
     * @return #
     */
    public function edit(){
        if(I("request.id")){
            $map['id']  =I("request.id",'','int');
        }
        if(I("request.name")){
            $map['name']=I("request.name","","trim");
        }else{
            $this->error("原料名称不能为空");
        }
        if($this->db->edit($map)){
            $this->success("涂原料编辑成功");
        }else{
            $this->error("涂原料编辑失败");
        }
    }
    
    /*
     * 删除、批量删除涂原料
     * 
     * @return bool
     */
    public function del(){
        $map['id']  =I("request.id");
        if($this->db->del($map)){
            $this->success("删除成功");
        }else{
            $this->error("删除失败");
        }
    }
}
